<!--  edu_16_1_4.html -->
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>随机产生[m,n]区间内20个整数</title>
    <script  type="text/javascript">
        function $(id){return document.getElementById(id);}

        function createInt() {
            var m = parseFloat($("minN").value);//解析为实数
            var n = parseFloat($("maxN").value);//解析为实数
            var array_int = new Array();
            var array_int_2 = new Array();
            var j = 0;

            if (m >= n)    //合法性检验
            {
                alert("数组上、下限不能相同！重新输入");
                $("minN").focus();//让文本框自动获取焦点
            } else {
                for (var i = 0; i < 20; i++) { //产生 m-n 之间的随机数
                    array_int[i] = Math.round((Math.random() * (n - m) + m));


                }
                array_int.sort(function (a, b) {
                    return a - b;
                });//数组排序
            }
            $("array_num").value = array_int.join(",");


                for (var i = 0; i < 20; i++) {
                    if (array_int[i] % 5 === 0) {
                        array_int_2[j] = array_int[i];
                        j++;
                    }
                    array_int_2.sort(function (a, b) {
                        return a - b;
                    });//数组排序
                }
                $("ch_num").value = array_int_2.join(",");

        }
    </script>

</head><body>
<h3>随机产生[m,n]区间内20个整数</h3>
<form name="Form1">
    下限: <input type="text" name="minN" id="minN" size="20" value=1000>
    上限: <input type="text" name="maxN" id="maxN" size="20" value=9999><br><br>
    产生数组：<input type="text" name="" id="array_num" size="100" readonly><br><br>
    <input type="button" value="产生20个随机整数" onclick="createInt();"><br><br>
    能被5整除的整数：<input type="text" name="" id="ch_num" size="100" readonly><br><br>
   <input type="button" value="被5整除的数" onclick="createInt();">
    <input type="reset"><br><br>

</form></body></html>

